package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.atguigu.tingshu.user.properties.WechatAccountConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WeChatMpConfig {

    @Autowired
    private WechatAccountConfig wechatAccountConfig ;

    @Bean
    public WxMaService wxMaService() {

        // 请求微服务服务器完成登录操作
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl() ;
        wxMaConfig.setAppid(wechatAccountConfig.getAppId());
        wxMaConfig.setSecret(wechatAccountConfig.getAppSecret());
        // 数据传输格式
        wxMaConfig.setMsgDataFormat("JSON");
        WxMaService wxMaService = new WxMaServiceImpl() ;
        wxMaService.setWxMaConfig(wxMaConfig);

        return wxMaService ;

    }

}
